package com.example.esdemo.controller;

import com.example.esdemo.dao.SupplierRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EsController {
    @Autowired
    private SupplierRepository supplierRepository;
    @GetMapping("/test")
    public String test(){
        //查询所有
        supplierRepository.findAll().forEach(supplier -> System.out.println(supplier));
        //根据id查询
        System.out.println(supplierRepository.findById("1016"));
        //排序查询
        supplierRepository.findAll(Sort.by(Sort.Order.asc("name"))).forEach(supplier -> System.out.println(supplier));
        //根据name查询
        System.out.println(supplierRepository.findByName("腾讯"));
        //根据name和leader查询
        System.out.println(supplierRepository.findByNameAndLeader("腾讯","马化腾"));
        //根据name或者leader查询
        System.out.println(supplierRepository.findByNameOrLeader("0001","马化腾"));
        return "ok";
    }
}
